package com.angel.web.health;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.angel.core.util.JsonUtil;
import com.angel.core.util.Pager;
import com.angel.health.BuzLabel;
import com.angel.provider.health.BuzLabelProvider;

/**
 * 标签管理
 * @author gao
 *
 */
@Controller
@RequestMapping("label")
public class BuzLabelController {
	
	@Autowired
	BuzLabelProvider lebelService;

	@RequestMapping("index")
	public String index(HttpServletRequest request,BuzLabel buzLabel,Pager pager){
		
		Pager bean = lebelService.findAll(buzLabel,pager);
		request.setAttribute("pager", bean);
		return "customer/label";
	}
	
	@ResponseBody
	@RequestMapping("save")
	public String save(HttpServletRequest request,@ModelAttribute("buzLabel") BuzLabel buzLabel){
		BuzLabel label = new BuzLabel();
		label.setName(buzLabel.getName());
		List<Map<String,Object>> list = lebelService.findAll(label);
		if(list.size() > 0){
			return "0";
		}
		lebelService.insert(buzLabel);
		return JsonUtil.toJson("1");
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public String update(BuzLabel buzLabel,HttpServletRequest request){
		int i = lebelService.updateById(buzLabel);
		return JsonUtil.toJson(i);
	}

}
